<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="ajax.js"></script>
<script type="text/javascript">

function showAddress(zipcode,sido,gugun,dong,seq){
	//화면에서 자신을 띄운 쪽으로 접근 할시에 opener를 사용한다.
	opener.document.registerForm.zipcode.value=zipcode;
	opener.document.registerForm.address.value=sido+gugun+dong;
	opener.document.registerForm.seq.value=seq;
	window.close();
}
function addressSearch(){
	var dong = document.searchForm.dong;
	var form = document.searchForm;
	 
	if(dong.value==""){
		alert("동을 입력하세요");
		
		return false;
	}
	form.action = "/${initParam.context_root}/addressSearch.do?dong="+dong.value;
	form.method = "get";
	form.submit();
}

</script>
</head>
<body>
<form name="searchForm">

동을 입력하세요<br>
<input type="text" name="dong"><input type="button" value="찾기" onclick="addressSearch()"><p>
<!-- 링크에서 자바스크립트를 실행할때에는 javascript:을 사용한다. -->
<c:forEach items="${requestScope.list }" var="adto">
<a href="javascript:showAddress('${adto.zipcode}','${adto.sido}','${adto.gugun}','${adto.dong }','${adto.seq }')">우편번호 : ${adto.zipcode}<br>
시도 : ${adto.sido}
군 : ${adto.gugun}
동 : ${adto.dong }
번지 : ${adto.bunji }
seq : ${adto.seq }<br></a>
<hr>
</c:forEach>

<button onclick="window.close()">닫기</button>

</form>
</body>
</html>